#pragma once

#include "Protocol.hpp"
#include <memory>

class NetCal
{
public:
    NetCal() {}
    ~NetCal() {}
    std::shared_ptr<Response> Calculator(std::shared_ptr<Request> req)
    {
        auto resp = Factor::BuildResponse();
        switch (req->_opera)
        {
        case '+':
            resp->_result = req->_x + req->_y;
            break;
        case '-':
            resp->_result = req->_x - req->_y;
            break;
        case '*':
            resp->_result = req->_x * req->_y;
            break;
        case '/':
        {
            if (req->_y == 0)
            {
                resp->_code = 1;
                resp->_desc = "div zero";
            }
            else
                resp->_result = req->_x / req->_y;
        }
        break;
        case '%':
        {
            if (req->_y == 0)
            {
                resp->_code = 2;
                resp->_desc = "mod zero";
            }
            else
                resp->_result = req->_x % req->_y;
        }
        break;
        default:
            resp->_code = 3;
            resp->_desc = "illegal operator";
            break;
        }

        return resp;
    }
};